package org.zjt.platform.spring.boot.example.api;

import org.zjt.platform.spring.boot.example.entity.TestPOJO;
import org.zjt.platform.spring.boot.example.service.IRabbitMsgService;
import org.zjt.platform.spring.boot.example.service.ITestService;
import org.zjt.platform.spring.boot.example.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @author <a href="juntao.zhang@qq.com">juntao.zhang</a>
 * @Description:
 * @Package org.zjt.platform.spring.boot.example.api
 * @date 2018/3/14 11:29
 * @see
 */
@RestController
public class HelloController {


    @Autowired
    private RedisTemplate redisTemplate ;

    @Autowired
    private ITestService iTestService;

    @Autowired
    private IRabbitMsgService iRabbitMsgService;


    @GetMapping("redis/set/{name}:{value}")
    public JsonResult<String> redisTest(@PathVariable(name = "name")String name, @PathVariable(name = "value")String value) {
        redisTemplate.boundValueOps(name).set(value);
        return JsonResult.OK();
    }


    @GetMapping("mybaits/query/{id}")
    public JsonResult<List<TestPOJO>> redisTest(@PathVariable(name = "id")Long id) {
        return JsonResult.OK(iTestService.get(id));
    }

    @GetMapping("rabbit/send/{mq}/{content}")
    public JsonResult<List<TestPOJO>> rabbitTest(@PathVariable(name = "mq")String mq, @PathVariable(name = "content")String content) {
        if (Objects.equals("auto",mq))
            iRabbitMsgService.sendAutoMsg(content);
        else if (Objects.equals("manual",mq))
            iRabbitMsgService.sendManualMsg(content);
        else
            throw new IllegalArgumentException("mq ");
        return JsonResult.OK();
    }
}
